/**
 *<p>Copyright: CHINA NATIONAL SOFTWARE & SERVICE CO.,LTD.</p>
 */
package com.cssnb.wwxt.xxtx.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cssnb.wwxt.msg.dao.MsgMapper;

/**
 * @Company: 中国软件与技术服务股份有限公司宁波子公司
 * @Project: 宁波市国税-外维系统
 * @Module ID:
 * @Description:
 * @JDK version used: JDK1.6
 * @Author: 卜繁晟
 * @Email: 5545795@qq.com | bufsh@css.com.cn
 * @Created Date: 2013-5-24 下午3:50:57
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Service
public class MsgService implements IMsgService {

	@Autowired
	private MsgMapper msgMapper;
	private Map pMap;

	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public int addMessage(String title, String content, String url, String sender, String receiver, String sendTime, int type){
		pMap = new HashMap();
		pMap.put("TITLE", title);
		pMap.put("CONTENT", content);
		pMap.put("URL", url);
		pMap.put("SENDER", sender);
		pMap.put("SENDTIME", sendTime);
		pMap.put("RECEIVER", receiver);
		pMap.put("TYPE", type);
		int res = msgMapper.addMessage(pMap);
		if(res > 0){
			return msgMapper.addMessageInfo(pMap);
		}else{
			return res;
		}
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public int delMessage(int msgId){
		pMap = new HashMap();
		pMap.put("MSGID", msgId);
		return msgMapper.delMessage(pMap);
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public int updMessage(String title, String content, String url, String sender, String sendTime, int type, int msgId){
		pMap = new HashMap();
		pMap.put("TITLE", title);
		pMap.put("CONTENT", content);
		pMap.put("URL", url);
		pMap.put("SENDER", sender);
		pMap.put("SENDTIME", sendTime);
		pMap.put("TYPE", type);
		pMap.put("MSGID", msgId);
		return msgMapper.updMessage(pMap);
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public int getMessageCount(String sender, int type, String title, String content, String sendTimeBegin, String sendTimeEnd){
		pMap = new HashMap();
		if(sender != null || !"".equals(sender)){
			pMap.put("SENDER", sender);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		if(title != null || !"".equals(title)){
			pMap.put("TITLE", title);
		}
		if(content != null || !"".equals(content)){
			pMap.put("CONTENT", content);
		}
		if(sendTimeBegin != null || !"".equals(sendTimeBegin)){
			pMap.put("SENDTIMEBEGIN", sendTimeBegin);
		}
		if(sendTimeEnd != null || !"".equals(sendTimeEnd)){
			pMap.put("SENDTIMEEND", sendTimeEnd);
		}
		return msgMapper.getMessageCount(pMap);
	}
	/**
	 * 根据接收者查询消息总数
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-27 上午11:28:10
	 */
	public int getMessageCount(String receiver, int type){
		pMap = new HashMap();
		if(receiver != null || !"".equals(receiver)){
			pMap.put("RECEIVER", receiver);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		return msgMapper.getMessageCount(pMap);
	}
	/**
	 * 根据接收者查询消息总数
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-27 上午11:28:10
	 */
	public int getMessageCount(String receiver, int type, String sendTimeBegin, String sendTimeEnd){
		pMap = new HashMap();
		if(receiver != null || !"".equals(receiver)){
			pMap.put("RECEIVER", receiver);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		return msgMapper.getMessageCount(pMap);
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public List getMessageList(String sender, int type, String title, String content, String sendTimeBegin, String sendTimeEnd){
		pMap = new HashMap();
		if(sender != null || !"".equals(sender)){
			pMap.put("SENDER", sender);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		if(title != null || !"".equals(title)){
			pMap.put("TITLE", title);
		}
		if(content != null || !"".equals(content)){
			pMap.put("CONTENT", content);
		}
		if(sendTimeBegin != null || !"".equals(sendTimeBegin)){
			pMap.put("SENDTIMEBEGIN", sendTimeBegin);
		}
		if(sendTimeEnd != null || !"".equals(sendTimeEnd)){
			pMap.put("SENDTIMEEND", sendTimeEnd);
		}
		return msgMapper.getMessageList(pMap);
	}
	/**
	 * 根据接收者查询消息列表
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-27 上午11:27:47
	 */
	public List getMessageList(String receiver, int type){
		pMap = new HashMap();
		if(receiver != null || !"".equals(receiver)){
			pMap.put("RECEIVER", receiver);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		List list = msgMapper.getMessageList(pMap);
		return list;
	}
	/**
	 * 根据接收者查询消息列表
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-27 上午11:27:47
	 */
	public List getMessageList(String receiver, int type, String sendTimeBegin, String sendTimeEnd){
		pMap = new HashMap();
		if(receiver != null || !"".equals(receiver)){
			pMap.put("RECEIVER", receiver);
		}
		if(type != -1){
			pMap.put("TYPE", type);
		}
		return msgMapper.getMessageList(pMap);
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-5-24 下午3:51:09
	 */
	@Override
	public Map getMessage(int msgId){
		pMap = new HashMap();
		pMap.put("MSGID", msgId);
		return msgMapper.getMessage(pMap);
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-13 下午2:43:08
	 */
	@Override
	public List getMessageReport(){
		return msgMapper.getMessageReport();
	}
	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-6-28 下午2:52:04
	 */
	@Override
	public String say(String word){
		return word;
	}
}